using System;
using System.Text;
using UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding;

namespace Windows.Storage
{
    internal static class EncodingExtensions
    {
        /// <summary>
        /// Convert Windows Runtime encoding enum to CLI encoding type.
        /// </summary>
        public static Encoding ToEncoding(this UnicodeEncoding unicodeEncoding)
        {
            switch (unicodeEncoding)
            {
                case UnicodeEncoding.Utf8:
                    return Encoding.UTF8;
                case UnicodeEncoding.Utf16LE:
                    return Encoding.Unicode;
                case UnicodeEncoding.Utf16BE:
                    return Encoding.BigEndianUnicode;
                default:
                    throw new ArgumentOutOfRangeException("unicodeEncoding");
            }
        }
    }
}